package com.heima.article.controller.v1;


import com.heima.article.service.ApArticleservice;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {


    @Autowired
    private ApArticleservice apArticleservice;

    /**
     * 加载首页
     *
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
//        return apArticleservice.load(dto, 3);
        return apArticleservice.loadFromRedis(dto);
    }


    /**
     * 最多
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto) {
        return apArticleservice.load(dto, 1);
    }

    /**
     * 加载最新
     *
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {
        return apArticleservice.load(dto, 2);
    }




    /**
     * 新增article三剑客的接口
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveAparticle(@RequestBody ArticleDto dto){
        return apArticleservice.saveAparticle(dto);
    }



}
